<?php
class MixedDataHandle extends AbsDataHandle {
	private static $options = array(
		'value' => null,
		'handles' => 'bool,float,int,string,null',
	);
	
	public static function getType() {
		return 'mixed';
	}
	
	public static function handle($defineCfg) {
		$options = (isset($defineCfg['options']) && is_array($defineCfg['options'])) ? $defineCfg['options'] : array();
		
		$options = array_merge(self::$options, $options);
		
		return self::genData($options);
	}
	
	private static function genData($options) {
		if(null !== $options['value']) $data = $options['value'];
		else {
			$typeArr = explode(',', $options['handles']);
			$typeArr = array_filter($typeArr, array(__CLASS__, 'optionFilter'));
			$type = $typeArr[array_rand($typeArr)];
			
			$defineCfg = array(
				'type' => $type,
			);
			
			$data = DCenter::data($defineCfg, DCenter::getCfg());
		}
		
		return $data;
	}
	
	private static function optionFilter($val) {
		$clz = ucfirst(strtolower($val)) . 'DataHandle';
		
		return class_exists($clz) ? true : false;
	}
}
?>